package com.sgj.principle.demeter.improve;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 迪米特法则
 * @Author: Guoji Shen
 * @Date: 2021/11/11 00943
 */
public class Demeter1 {
    public static void main(String[] args) {
        SchoolManager schoolManager = new SchoolManager();
        schoolManager.printAllEmployee(new CollegeManager());
    }
}

// 学校总部员工
@Data
class Employee {
    private String id;
}

// 学院员工
@Data
class CollegeEmployee {
    private String id;
}

// 管理学院员工的管理类
class CollegeManager {
    // 返回所有员工
    public List<CollegeEmployee> getAllEmployee() {
        List<CollegeEmployee> list = new ArrayList<>();
        for (int i = 1; i <= 10; i++) {
            CollegeEmployee emp = new CollegeEmployee();
            emp.setId("学院员工id = " + i);
            list.add(emp);
        }
        return list;
    }

    // 获取学院员工
    public void printEmployee() {
        List<CollegeEmployee> list1 = this.getAllEmployee();
        System.out.println("-------------分公司员工-------------");
        for (CollegeEmployee e : list1) {
            System.out.println(e.getId());
        }
    }
}

// 学校管理类
class SchoolManager {
    // 返回学校总部的员工
    public List<Employee> getAllEmployee() {
        List<Employee> list = new ArrayList<>();
        for (int i = 1; i <= 5; i++) {
            Employee emp = new Employee();
            emp.setId("学校总部员工id = " + i);
            list.add(emp);
        }
        return list;
    }

    // 该方法完成输出学校总部和学院员工信息(id)
    void printAllEmployee(CollegeManager sub) {

        /**
         * 分析问题
         * 1、将输出学院的员工方法，封装到 CollegeManager
         * 2、直接调用输出方法
         */

        sub.printEmployee();
        // 获取学校总部员工
        List<Employee> list2 = this.getAllEmployee();
        System.out.println("-------------学校总部员工-------------");
        for (Employee e : list2) {
            System.out.println(e.getId());
        }
    }
}